package x.y.z;

import java.util.HashSet;
import java.util.Set;

public class Interview_1_1_IsUnique {
    public boolean isUnique(String astr) {
        char[] chs = astr.toCharArray();
        Set<Character> sets = new HashSet<>();
        for (char ch : chs) {
            if (sets.contains(ch)) {
                return false;
            }
            sets.add(ch);
        }
        return true;
    }

    public boolean isUnique_1(String astr) {
        if (astr.length() > 128) {
            return false;
        }
        boolean[] chs = new boolean[128];
        for (int i = 0; i < astr.length(); i++) {
            int val = astr.charAt(i);
            if (chs[val]) {
                return false;
            }
            chs[val] = true;
        }
        return true;
    }
}